<p>Possessive quantifiers in Regex patterns like below improve performance by eliminating needless backtracking:</p>
<pre>
?+ , *+ , ++ , {n}+ , {n,}+ , {n,m}+
</pre>
<p>But because possessive quantifiers do not keep backtracking positions and never give back, the following sub-patterns should not match only similar
characters. Otherwise, possessive quantifiers consume all characters that could have matched the following sub-patterns and nothing remains for the
following sub-patterns.</p>
<h2>Noncompliant Code Example</h2>
<pre>
Pattern pattern1 = Pattern.compile("a++abc");       // Noncompliant, the second 'a' never matches
Pattern pattern2 = Pattern.compile("\\d*+[02468]"); // Noncompliant, the sub-pattern "[02468]" never matches
</pre>
<h2>Compliant Solution</h2>
<pre>
Pattern pattern1 = Pattern.compile("aa++bc");            // Compliant, for example it can match "aaaabc"
Pattern pattern2 = Pattern.compile("\\d*+(?&lt;=[02468])"); // Compliant, for example it can match an even number like "1234"
</pre>

